package org.apmap.common;

import org.apache.commons.beanutils.BeanUtils;
import org.apmap.base.OfferType;
import org.apmap.base.Office;

public class Utils {

    public static double MULTI = 1000000000000000.0;

    public static long parseGeo(String str) {
        return (long) (MULTI * Double.parseDouble(str));
    }

    public static void copyGeo(org.apmap.base.Flat flatFrom, org.apmap.base.Flat flatTo) {
        flatTo.setLat(flatFrom.getLat());
        flatTo.setLatLong((long) (flatFrom.getLat() * MULTI));
        flatTo.setLng(flatFrom.getLng());
        flatTo.setLngLong((long) (flatFrom.getLng() * MULTI));
    }

    public static void copyGeo(Office flatFrom, Office flatTo) {
        flatTo.setLat(flatFrom.getLat());
        flatTo.setLatLong((long) (flatFrom.getLat() * MULTI));
        flatTo.setLng(flatFrom.getLng());
        flatTo.setLngLong((long) (flatFrom.getLng() * MULTI));
    }

    public static void prepareBeforeSave(org.apmap.base.Flat flat) {
        flat.setLatLong((long) (flat.getLat() * MULTI));
        flat.setLngLong((long) (flat.getLng() * MULTI));

        flat.setType(OfferType.RENT);
        flat.setAddress("");
        flat.setRoomNumber((byte) 0);
        flat.setSquare(0);
        flat.setFloor((byte) 0);
        flat.setPrice(0.0);
        flat.setCurrency(Currency.USD);
        flat.setComment("");
    }

    public static void prepareBeforeSave(Office office) {
        office.setLatLong((long) (office.getLat() * MULTI));
        office.setLngLong((long) (office.getLng() * MULTI));

        office.setType(OfferType.RENT);
        office.setAddress("");
        office.setRoomNumber((byte) 0);
        office.setSquare(0);
        office.setFloor((byte) 0);
        office.setPrice(0.0);
        office.setCurrency(Currency.USD);
        office.setComment("");
    }

    public static void main(String[] args) throws Exception {
        org.apmap.base.Flat flat1 = new org.apmap.base.Flat();
        org.apmap.beans.Flat flat2 = new org.apmap.beans.Flat();


        flat1.setId(100);
        flat1.setLat(1.23);
//        flat1.setLatLong(123);

        BeanUtils.copyProperties(flat2, flat1);

        System.out.println("flat2.getId() = " + flat2.getId());
        System.out.println("flat2.getLat() = " + flat2.getLat());
    }
}
